package com.iking.toolkit.util;

import com.iking.toolkit.redis.RedisObjectService;
import com.iking.toolkit.system.dao.DictionaryItemsMapper;
import com.iking.toolkit.system.model.model.DictionaryItems;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 *
 * 功能描述:对接ApiURL的工具类
 * @author: yfl
 * @date: 2025/8/4 18:03
 */
@Slf4j
@Component
public class ApiUrlUtil {

    @Autowired
    private RedisObjectService<String> redisObjectService;

    @Autowired
    private DictionaryItemsMapper dictionaryItemsMapper;
    public String getOcrApiUrl() {
        String ocrApiUrl =  redisObjectService.get("ocrApiUrl");
        if (StringUtils.isBlank(ocrApiUrl)) {
            DictionaryItems dictionaryItems = dictionaryItemsMapper.selectByTypeIdAndPym("ocrApiUrl", "api_url");
            if (dictionaryItems == null) {
                return null;
            }
            ocrApiUrl = dictionaryItems.getItemValue();
            redisObjectService.set("ocrApiUrl", ocrApiUrl);
        }
        return ocrApiUrl;
    }
}
